<ot-view>

    <form ng-submit="submitSearch()">
        <table class="table table-hover table-condensed">
            <thead>
            <tr>
                <th>Branch</th>
                <th>Build</th>
                <th>Promotions</th>
                <th>Validations</th>
                <th>&nbsp;</th>
            </tr>
            </thead>
            <!-- Form -->
            <tbody>
            <tr>
                <td>
                    <input name="branchName" ng-model="data.branchName" class="form-control input-sm" type="text"
                           placeholder="Branch name"/>
                </td>
                <td>
                    <input name="buildName" ng-model="data.buildName" class="form-control input-sm" type="text"
                           placeholder="Build name"/>
                </td>
                <td>
                    <input name="promotionName" ng-model="data.promotionName" class="form-control input-sm" type="text"
                           placeholder="Promotion name"/>
                </td>
                <td>
                    <input name="validationStampName" ng-model="data.validationStampName" class="form-control input-sm"
                           type="text"
                           placeholder="Validation stamp name"/>
                </td>
                <td>
                    <button class="btn btn-sm btn-primary" type="submit" ng-hide="searching">
                        <span class="fa fa-search"></span>
                        Search
                    </button>
                    <button class="btn btn-sm btn-primary" type="submit" ng-show="searching" disabled="disabled">
                        <span class="fa fa-spinner fa-spin"></span>
                        Searching
                    </button>
                    <button class="btn btn-sm btn-info"
                            ng-repeat="buildDiffAction in buildDiffActions"
                            ng-click="buildDiff(buildDiffAction)"
                            ng-disabled="!selectedBuild.from || !selectedBuild.to">
                        {{buildDiffAction.name}}
                    </button>
                    <button class="btn btn-sm btn-link" type="button"
                            ng-class="{'text-muted': advancedSearch}"
                            title="Displays additional search options."
                            ng-click="toggleAdvancedSearch()">
                        Advanced
                    </button>
                    <button class="btn btn-sm btn-link" type="button"
                            title="Clears the search options."
                            ng-click="resetForm()">
                        Reset
                    </button>
                    <button class="btn btn-sm btn-link" type="button"
                            title="Displays the permalink in the address bar."
                            ng-click="displayPermalink()">
                        <span class="fa fa-link"></span>
                    </button>
                </td>
            </tr>
            <tr ng-show="advancedSearch">
                <td colspan="1">
                    Max. count
                    <input name="maximumCount" ng-model="data.maximumCount"
                           class="form-control input-sm"
                           type="number" min="1"
                           placeholder="Maximum count"/>
                </td>
                <td>
                    Linked from
                    <span class="fa fa-question-circle text-muted"
                          title="The build must be linked FROM the builds selected by the pattern. Syntax: PRJ:BLD where PRJ is a project name and BLD a build expression - with * as placeholder"></span>
                    <input name="linkedFrom" ng-model="data.linkedFrom"
                           class="form-control input-sm"/>
                </td>
                <td>
                    Linked to
                    <span class="fa fa-question-circle text-muted"
                          title="The build must be linked TO the builds selected by the pattern. Syntax: PRJ:BLD where PRJ is a project name and BLD a build expression - with * as placeholder"></span>
                    <input name="linkedTo" ng-model="data.linkedTo"
                           class="form-control input-sm"/>
                </td>
                <td>
                    Property
                    <select ng-model="data.property"
                            ng-options="item.typeName as item.name for item in propertyField.items"
                            class="form-control input-sm">
                        <option value="">&nbsp;</option>
                    </select>
                </td>
                <td>
                    Property value
                    <input name="propertyValue" ng-model="data.propertyValue"
                           class="form-control input-sm"/>
                </td>
            </tr>
            </tbody>
            <!-- Selected builds -->
            <tbody>
            <tr ng-repeat="buildView in selectedBuilds" class="ot-build-search-build ot-build-search-build-selected">
                <td class="ot-build-search-build-name">
                    <a href="#/branch/{{buildView.build.branch.id}}">{{buildView.build.branch.name}}</a>
                </td>
                <td class="ot-build-search-build-name">
                    <a href="#/build/{{buildView.build.id}}">{{buildView.build.name}}</a>
                </td>
                <td>
                    <ot-build-promotion-runs promotion-runs="buildView.promotionRuns"></ot-build-promotion-runs>
                </td>
                <td>
                <span ng-repeat="validationStampRunView in buildView.validationStampRunViews"
                      ng-if="validationStampRunView.passed">
                    <ot-entity-image entity="validationStampRunView.validationStamp"></ot-entity-image>
                </span>
                </td>
                <td>
                    <span class="fa fa-minus ot-command"
                          ng-click="unselectBuild(buildView)"
                          title="Unselect this build."></span>
                    <input type="radio" id="build-from-{{buildView.build.id}}-selected" name="selectedBuildFrom"
                           ng-model="selectedBuild.from" ng-value="buildView.build.id"/>
                    <input type="radio" id="build-to-{{buildView.build.id}}-selected" name="selectedBuildTo"
                           ng-model="selectedBuild.to" ng-value="buildView.build.id"/>
                </td>
            </tr>
            </tbody>
            <!-- No results -->
            <tbody ng-show="searched && buildViews.length == 0">
            <tr>
                <td colspan="5">
                    <div class="alert alert-warning">
                        No build has been found.
                    </div>
                </td>
            </tr>
            </tbody>
            <!-- Results -->
            <tbody ng-show="buildViews">
            <tr ng-repeat="buildView in buildViews" class="ot-build-search-build">
                <td>
                    <a href="#/branch/{{buildView.build.branch.id}}">{{buildView.build.branch.name}}</a>
                </td>
                <td>
                    <a href="#/build/{{buildView.build.id}}">{{buildView.build.name}}</a>
                </td>
                <td>
                    <ot-build-promotion-runs promotion-runs="buildView.promotionRuns"></ot-build-promotion-runs>
                </td>
                <td>
                <span ng-repeat="validationStampRunView in buildView.validationStampRunViews"
                      ng-if="validationStampRunView.passed">
                    <ot-entity-image entity="validationStampRunView.validationStamp"></ot-entity-image>
                </span>
                </td>
                <td>
                    <span class="fa fa-plus ot-command"
                          ng-click="selectBuild(buildView)"
                          title="Select this build."></span>
                </td>
            </tr>
            </tbody>
        </table>
    </form>

</ot-view>